<%-- 
    Document   : c_foreach
    Created on : 2012-12-13, 16:06:06
    Author     : Administrator
--%>


<%@page contentType="text/html"  import="com.hsp.domain.*, java.util.*" pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
    </head>
    <body>
        <h1>迭代标签c:foreach</h1>

        <%
            ArrayList<Rat> al = new ArrayList<Rat>();

            Rat rat1 = new Rat();
            rat1.setName("小宝");
            rat1.setAge(2);

            Rat rat2 = new Rat();
            rat2.setName("大宝");
            rat2.setAge(4);

            Rat rat3 = new Rat();
            rat3.setName("老宝");
            rat3.setAge(8);

            //放到ArrayList中
            al.add(rat1);
            al.add(rat2);
            al.add(rat3);

            request.setAttribute("allrats", al);
        %>

        <h1>foreach的取法</h1>
        <c:forEach items="${allrats}" var="rat">

            <c:out value = "${rat.name}"/>
            <c:out value = "${rat.age}"/> 

        </c:forEach>

    </body>
</html>
